package com.diaohw.module.system.controller;

import com.diaohw.module.system.obj.dto.AccountInsertDto;
import com.diaohw.module.system.obj.dto.AccountUpdateDto;
import com.diaohw.module.system.obj.query.AccountQuery;
import com.diaohw.module.system.obj.vo.AccountVo;
import com.diaohw.module.system.service.AccountService;
import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.common.validator.InsertGroup;
import com.diaohw.platform.common.validator.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author D-Hw
 * @since 2024-07-05
 */
@Tag(name = "用户管理", description = "用户管理")
@RestController
@RequestMapping("/account")
public class AccountController {

    @Resource
    AccountService service;


    @PostMapping
    @Operation(summary = "新增")
    public AccountVo create(@RequestBody @Validated(InsertGroup.class) AccountInsertDto data) {
        return service.create(data);
    }

    @PutMapping("{id}")
    @Operation(summary = "更新")
    public AccountVo update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) AccountUpdateDto data) {
        return service.update(id, data);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "查看指定用户信息")
    public AccountVo detail(@PathVariable("id") String id) {
        return service.detail(id);
    }

    @GetMapping
    @Operation(summary = "查询列表")
    public List<AccountVo> all(AccountQuery query) {
        return service.findByList(query);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<AccountVo> page(AccountQuery query) {
        return service.findByPage(query);
    }

}
